package com.itheima.bos.web.action.take_delivery;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheima.bos.domain.take_delivery.Order;
import com.itheima.bos.service.base.IOrderService;
import com.itheima.bos.web.action.base.BaseAction;
import com.opensymphony.xwork2.ActionContext;

/**
 * 后台处理订单的action
 * @author yanju
 *
 */
@Namespace("/")
@ParentPackage("json-default")
@Scope("prototype")
@Controller
public class OrderAction extends BaseAction<Order>{
	
	@Autowired
	private IOrderService orderServiceImpl;
	
	//处理订单号请求的action
	@Action(value="order_findByOrderNum",results={@Result(name="success",type="json")})
	public String findByOrderNum(){
		Map<String,Object> map = new HashMap<String, Object>();
		
		Order order=orderServiceImpl.findByOrderNum(model.getOrderNum());
		
		if (order==null) {
			//订单不存在
			map.put("success",false);
		}else{
			map.put("success",true);
			map.put("orderData",order);
		}
			ActionContext.getContext().getValueStack().push(map);
		return "success";
	}
	
}
